using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Hector.Api.Ddl;
using Org.Apache.Cassandra.Thrift;

namespace Me.Prettyprint.Cassandra.Service
{
	public class ThriftColumnDef : ColumnDefinition
	{
		public ThriftColumnDef(ColumnDef cd)
		{
			Name = cd.Name;
			ValidationClass = cd.Validation_class;
			IndexType = IndexTypeFromThrift(cd.Index_type);
			IndexName = cd.Index_name;
		}
		
		public ThriftColumnDef(ColumnDefinition columnDefinition)
		{
			Name = columnDefinition.Name;
			ValidationClass = columnDefinition.ValidationClass;
            IndexType = columnDefinition.IndexType;
			IndexName = columnDefinition.IndexName;
		}
        public byte[] Name
        {
            get;set;
        }
        public string ValidationClass
        {
            get;set;
        }
        public ColumnIndexType IndexType
        {
            get;set;
        }
        public string IndexName
        {
            get;set;
        }
		private ColumnIndexType IndexTypeFromThrift(IndexType tIndexType)
		{
            if (tIndexType == null)
            {
				return ColumnIndexType.KEYS;
            }
			switch (tIndexType)
			{
				
				case Org.Apache.Cassandra.Thrift.IndexType.KEYS: 
					return ColumnIndexType.KEYS;
				
				case Org.Apache.Cassandra.Thrift.IndexType.CUSTOM: 
					return ColumnIndexType.CUSTOM;
				
				default: 
					throw new System.SystemException("Unknown thrift IndexType: " + tIndexType);
				
			}
		}
		public static List<ColumnDefinition> FromThriftList(List < ColumnDef > columnDefs)
        {
            if (columnDefs == null || columnDefs.Count == 0)
            {
                return new List<ColumnDefinition>();
            }
            List<ColumnDefinition> list = new List<ColumnDefinition>(columnDefs.Count);
            foreach (ColumnDef cd in columnDefs)
            {
                list.Add(new ThriftColumnDef(cd));
            }
            return list;
        }
        public static List<ColumnDef> ToThriftList(List<ColumnDefinition> columnDefs)
        {
            if (columnDefs == null || columnDefs.Count == 0)
            {
                return new List<ColumnDef>();
            }
            List<ColumnDef> list = new List<ColumnDef>(columnDefs.Count);
            foreach (ColumnDefinition d in columnDefs)
            {
                list.Add((new ThriftColumnDef(d)).toThrift());
            }
            return list;
        }
		
		private ColumnDef toThrift()
		{
			ColumnDef d = new ColumnDef();
			if (IndexName != null)
			{
				d.Index_name = IndexName;
				d.Index_type = IndexTypeToThrift(IndexType);
			}
			d.Name = Name;
			d.Validation_class = ValidationClass;
			return d;
		}
		
		private IndexType IndexTypeToThrift(ColumnIndexType indexType2)
		{
			switch (indexType2)
			{
				
				case ColumnIndexType.KEYS: 
					return Org.Apache.Cassandra.Thrift.IndexType.KEYS;
				
				case ColumnIndexType.CUSTOM: 
					return Org.Apache.Cassandra.Thrift.IndexType.CUSTOM;
				
				default: 
					throw new System.SystemException("Unknown ColumnIndexType value: " + indexType2);
				
			}
		}
		public override System.String ToString()
		{
			return typeof(ThriftColumnDef).ToString();
		}
	}
}